// System Unit
// ANSIString Support

(*************)
(* Interface *)
(*************)
{$IFDEF Include_Modules_Header}

 Const
  CodePage_UTF8 = 65001;
  CodePage_Raw  = $FFFF;

 Type
  PANSIString = ^ANSIString;

  UTF8String = Type ANSIString(CodePage_UTF8);
  PUTF8String = ^UTF8String;

  RawByteString = Type ANSIString(CodePage_Raw);
  PRawByteString = ^RawByteString;

 Function _PCharLen(P: PANSIChar): Integer;
 Type RTLProc_PCharLen = Function(P: PANSIChar): Integer;

 Function _LStrLen(Const S: ANSIString): Longint;
 Type RTLProc_LStrLen = Function(Const S: ANSIString): Longint;

 Function _NewANSIString(CharLength: Longint; CodePage: Word): Pointer;
 Type RTLProc_NewANSIString = Function(CharLength: Longint; CodePage: Word): Pointer;

 Procedure _LStrFromPCharLen(Var Dest: ANSIString; Source: PANSIChar; Length: Integer; CodePage: Word);
 Type RTLProc_LStrFromPCharLen = Procedure(Var Dest: ANSIString; Source: PANSIChar; Length: Integer; CodePage: Word);

 Procedure _LStrFromChar(Var Dest: ANSIString; Source: ANSIChar; CodePage: Word);
 Type RTLProc_LStrFromChar = Procedure(Var Dest: ANSIString; Source: ANSIChar; CodePage: Word);

 Procedure _LStrFromPChar(Var Dest: ANSIString; Source: PANSIChar; CodePage: Word);
 Type RTLProc_LStrFromPChar = Procedure(Var Dest: ANSIString; Source: PANSIChar; CodePage: Word);

 Procedure _LStrFromArray(Var Dest: ANSIString; Source: PANSIChar; Length: Integer; CodePage: Word);
 Type RTLProc_LStrFromArray = Procedure(Var Dest: ANSIString; Source: PANSIChar; Length: Integer; CodePage: Word);

 Function _LStrToPChar(Const S: ANSIString): PANSIChar;
 Type RTLProc_LStrToPChar = Function(Const S: ANSIString): PANSIChar;

 Procedure _LStrAsg(Var Dest: ANSIString; Const Source: ANSIString);
 Type RTLProc_LStrAsg = Procedure(Var Dest: ANSIString; Const Source: ANSIString);

 Procedure _LStrLAsg(Var Dest: ANSIString; Const Source: ANSIString);
 Type RTLProc_LStrLAsg = Procedure(Var Dest: ANSIString; Const Source: ANSIString);

 Function _UniqueStringA(Var Str: ANSIString): Pointer;
 Type RTLProc_UniqueStringA = Function(Var Str: ANSIString): Pointer;

 Function _AStrCmp(Const Left, Right: PANSIChar; Len: NativeInt): Integer;
 Type RTLProc_AStrCmp = Function(Const Left, Right: PANSIChar; Len: NativeInt): Integer;

 Function _LStrCmp(Const Left, Right: ANSIString): Integer;
 Type RTLProc_LStrCmp = Function(Const Left, Right: ANSIString): Integer;

 Function _LStrEqual(Const Left, Right: ANSIString): Integer;
 Type RTLProc_LStrEqual = Function(Const Left, Right: ANSIString): Integer;

 Function _LStrAddRef(Str: Pointer): Pointer;
 Type RTLProc_LStrAddRef = Function(Str: Pointer): Pointer;

 Function _LStrClr(Var S): Pointer;
 Type RTLProc_LStrClr = Function(Var S): Pointer;

 Procedure _LStrCat(Var Dest: ANSIString; Const Source: ANSIString);
 Type RTLProc_LStrCat = Procedure(Var Dest: ANSIString; Const Source: ANSIString);

 Procedure _LStrCat3(Var Dest: ANSIString; Const Source1, Source2: ANSIString);
 Type RTLProc_LStrCat3 = Procedure(Var Dest: ANSIString; Const Source1, Source2: ANSIString);

 Procedure _LStrCatN(Var Dest: ANSIString; ArgCnt: Integer; Const Strs: ANSIString {...});
 Type RTLProc_LStrCatN = Procedure(Var Dest: ANSIString; ArgCnt: Integer; Const Strs: ANSIString {...});

 Function _LStrCopy(Const Str: ANSIString; Index, Count: Integer): ANSIString;
 Type RTLProc_LStrCopy = Function(Const Str: ANSIString; Index, Count: Integer): ANSIString;

 Procedure _LStrDelete(Var S: ANSIString; Index, Count: Integer);
 Type RTLProc_LStrDelete = Procedure(Var S: ANSIString; Index, Count: Integer);

 Procedure _LStrInsert(Const Source: ANSIString; Var S: ANSIString; Index: Integer);
 Type RTLProc_LStrInsert = Procedure(Const Source: ANSIString; Var S: ANSIString; Index: Integer);

 Procedure _LStrSetLength(Var Str: ANSIString; NewLength: Integer; CodePage: Word);
 Type RTLProc_LStrSetLength = Procedure(Var Str: ANSIString; NewLength: Integer; CodePage: Word);

 Procedure _LStrArrayClr(Var StrArray; cnt: Longint);
 Type RTLProc_LStrArrayClr = Procedure(Var StrArray; cnt: Longint);

 Function _LStrPos(Const SubStr: ANSIString; Const S: ANSIString): Integer; // "Appendix" function?
 Type RTLProc_LStrPos = Function(Const SubStr: ANSIString; Const S: ANSIString): Integer;

 Procedure UniqueString(Var Str: ANSIString); Inline; Overload;

 //==================
 // RTL Extensions
 //==================
 Type
  TRTLEx_ANSIString = Record
   _PCharLen: RTLProc_PCharLen;
   _LStrLen: RTLProc_LStrLen;
   _NewANSIString: RTLProc_NewANSIString;
   _LStrFromPCharLen: RTLProc_LStrFromPCharLen;
   _LStrFromChar: RTLProc_LStrFromChar;
   _LStrFromPChar: RTLProc_LStrFromPChar;
   _LStrFromArray: RTLProc_LStrFromArray;
   _LStrToPChar: RTLProc_LStrToPChar;
   _LStrAsg: RTLProc_LStrAsg;
   _LStrLAsg: RTLProc_LStrLAsg;
   _UniqueStringA: RTLProc_UniqueStringA;
   _AStrCmp: RTLProc_AStrCmp;
   _LStrCmp: RTLProc_LStrCmp;
   _LStrEqual: RTLProc_LStrEqual;
   _LStrAddRef: RTLProc_LStrAddRef;
   _LStrClr: RTLProc_LStrClr;
   _LStrCat: RTLProc_LStrCat;
   _LStrCat3: RTLProc_LStrCat3;
   _LStrCopy: RTLProc_LStrCopy;
   _LStrCatN: RTLProc_LStrCatN;
   _LStrDelete: RTLProc_LStrDelete;
   _LStrInsert: RTLProc_LStrInsert;
   _LStrSetLength: RTLProc_LStrSetLength;
   _LStrArrayClr: RTLProc_LStrArrayClr;
   _LStrPos: RTLProc_LStrPos;
  END;

 Procedure RTLExtend_ANSIString(Var Ex: TRTLEx_ANSIString);

{$ENDIF Include_Modules_Header}
(******************)
(* Implementation *)
(******************)
{$IFDEF Include_Modules_Implement}

 Function _RTL_PCharLen(P: PANSIChar): Integer;
  ASM
   JMP _INT_NotImplemented
  END;

 Function _RTL_LStrLen(Const S: ANSIString): Longint;
  ASM
   JMP _INT_NotImplemented
  END;

 Function _RTL_NewANSIString(CharLength: Longint; CodePage: Word): Pointer;
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_LStrFromPCharLen(Var Dest: ANSIString; Source: PANSIChar; Length: Integer; CodePage: Word);
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_LStrFromChar(Var Dest: ANSIString; Source: ANSIChar; CodePage: Word);
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_LStrFromPChar(Var Dest: ANSIString; Source: PANSIChar; CodePage: Word);
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_LStrFromArray(Var Dest: ANSIString; Source: PANSIChar; Length: Integer; CodePage: Word);
  ASM
   JMP _INT_NotImplemented
  END;

 Function _RTL_LStrToPChar(Const S: ANSIString): PANSIChar;
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_LStrAsg(Var Dest: ANSIString; Const Source: ANSIString);
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_LStrLAsg(Var Dest: ANSIString; Const Source: ANSIString);
  ASM
   JMP _INT_NotImplemented
  END;

 Function _RTL_UniqueStringA(Var Str: ANSIString): Pointer;
  ASM
   JMP _INT_NotImplemented
  END;

 Function _RTL_AStrCmp(Const Left, Right: PANSIChar; Len: NativeInt): Integer;
  ASM
   JMP _INT_NotImplemented
  END;

 Function _RTL_LStrCmp(Const Left, Right: ANSIString): Integer;
  ASM
   JMP _INT_NotImplemented
  END;

 Function _RTL_LStrEqual(Const Left, Right: ANSIString): Integer;
  ASM
   JMP _INT_NotImplemented
  END;

 Function _RTL_LStrAddRef(Str: Pointer): Pointer;
  ASM
   JMP _INT_NotImplemented
  END;

 Function _RTL_LStrClr(Var S): Pointer;
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_LStrCat(Var Dest: ANSIString; Const Source: ANSIString);
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_LStrCat3(Var Dest: ANSIString; Const Source1, Source2: ANSIString);
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_LStrCatN(Var Dest: ANSIString; ArgCnt: Integer; Const Strs: ANSIString {...});
  ASM
   JMP _INT_NotImplemented
  END;

 Function _RTL_LStrCopy(Const Str: ANSIString; Index, Count: Integer): ANSIString;
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_LStrDelete(Var S: ANSIString; Index, Count: Integer);
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_LStrInsert(Const Source: ANSIString; Var S: ANSIString; Index: Integer);
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_LStrSetLength(Var Str: ANSIString; NewLength: Integer; CodePage: Word);
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_LStrArrayClr(Var StrArray; cnt: Longint);
  ASM
   JMP _INT_NotImplemented
  END;

 Function _RTL_LStrPos(Const SubStr: ANSIString; Const S: ANSIString): Integer;
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure UniqueString(Var Str: ANSIString);
  BEGIN
   _UniqueStringA(Str);
  END;

 Var
  RTL_PCharLen: RTLProc_PCharLen = _RTL_PCharLen;
  RTL_LStrLen: RTLProc_LStrLen = _RTL_LStrLen;
  RTL_NewANSIString: RTLProc_NewANSIString = _RTL_NewANSIString;
  RTL_LStrFromPCharLen: RTLProc_LStrFromPCharLen = _RTL_LStrFromPCharLen;
  RTL_LStrFromChar: RTLProc_LStrFromChar = _RTL_LStrFromChar;
  RTL_LStrFromPChar: RTLProc_LStrFromPChar = _RTL_LStrFromPChar;
  RTL_LStrFromArray: RTLProc_LStrFromArray = _RTL_LStrFromArray;
  RTL_LStrToPChar: RTLProc_LStrToPChar = _RTL_LStrToPChar;
  RTL_LStrAsg: RTLProc_LStrAsg = _RTL_LStrAsg;
  RTL_LStrLAsg: RTLProc_LStrLAsg = _RTL_LStrLAsg;
  RTL_UniqueStringA: RTLProc_UniqueStringA = _RTL_UniqueStringA;
  RTL_AStrCmp: RTLProc_AStrCmp = _RTL_AStrCmp;
  RTL_LStrCmp: RTLProc_LStrCmp = _RTL_LStrCmp;
  RTL_LStrEqual: RTLProc_LStrEqual = _RTL_LStrEqual;
  RTL_LStrAddRef: RTLProc_LStrAddRef = _RTL_LStrAddRef;
  RTL_LStrClr: RTLProc_LStrClr = _RTL_LStrClr;
  RTL_LStrCat: RTLProc_LStrCat = _RTL_LStrCat;
  RTL_LStrCat3: RTLProc_LStrCat3 = _RTL_LStrCat3;
  RTL_LStrCopy: RTLProc_LStrCopy = _RTL_LStrCopy;
  RTL_LStrCatN: RTLProc_LStrCatN = _RTL_LStrCatN;
  RTL_LStrDelete: RTLProc_LStrDelete = _RTL_LStrDelete;
  RTL_LStrInsert: RTLProc_LStrInsert = _RTL_LStrInsert;
  RTL_LStrSetLength: RTLProc_LStrSetLength = _RTL_LStrSetLength;
  RTL_LStrArrayClr: RTLProc_LStrArrayClr = _RTL_LStrArrayClr;
  RTL_LStrPos: RTLProc_LStrPos = _RTL_LStrPos;

 Function _PCharLen(P: PANSIChar): Integer;
  ASM
   JMP RTL_PCharLen
  END;

 Function _LStrLen(Const S: ANSIString): Longint;
  ASM
   JMP RTL_LStrLen
  END;

 Function _NewANSIString(CharLength: Longint; CodePage: Word): Pointer;
  ASM
   JMP RTL_NewANSIString
  END;

 Procedure _LStrFromPCharLen(Var Dest: ANSIString; Source: PANSIChar; Length: Integer; CodePage: Word);
  ASM
   JMP RTL_LStrFromPCharLen
  END;

 Procedure _LStrFromChar(Var Dest: ANSIString; Source: ANSIChar; CodePage: Word);
  ASM
   JMP RTL_LStrFromChar
  END;

 Procedure _LStrFromPChar(Var Dest: ANSIString; Source: PANSIChar; CodePage: Word);
  ASM
   JMP RTL_LStrFromPChar
  END;

 Procedure _LStrFromArray(Var Dest: ANSIString; Source: PANSIChar; Length: Integer; CodePage: Word);
  ASM
   JMP RTL_LStrFromArray
  END;

 Function _LStrToPChar(Const S: ANSIString): PANSIChar;
  ASM
   JMP RTL_LStrToPChar
  END;

 Procedure _LStrAsg(Var Dest: ANSIString; Const Source: ANSIString);
  ASM
   JMP RTL_LStrAsg
  END;

 Procedure _LStrLAsg(Var Dest: ANSIString; Const Source: ANSIString);
  ASM
   JMP RTL_LStrLAsg
  END;

 Function _UniqueStringA(Var Str: ANSIString): Pointer;
  ASM
   JMP RTL_UniqueStringA
  END;

 Function _AStrCmp(Const Left, Right: PANSIChar; Len: NativeInt): Integer;
  ASM
   JMP RTL_AStrCmp
  END;

 Function _LStrCmp(Const Left, Right: ANSIString): Integer;
  ASM
   JMP RTL_LStrCmp
  END;

 Function _LStrEqual(Const Left, Right: ANSIString): Integer;
  ASM
   JMP RTL_LStrEqual
  END;

 Function _LStrAddRef(Str: Pointer): Pointer;
  ASM
   JMP RTL_LStrAddRef
  END;

 Function _LStrClr(Var S): Pointer;
  ASM
   JMP RTL_LStrClr
  END;

 Procedure _LStrCat(Var Dest: ANSIString; Const Source: ANSIString);
  ASM
   JMP RTL_LStrCat
  END;

 Procedure _LStrCat3(Var Dest: ANSIString; Const Source1, Source2: ANSIString);
  ASM
   JMP RTL_LStrCat3
  END;

 Procedure _LStrCatN(Var Dest: ANSIString; ArgCnt: Integer; Const Strs: ANSIString {...});
  ASM
   JMP RTL_LStrCatN
  END;

 Function _LStrCopy(Const Str: ANSIString; Index, Count: Integer): ANSIString;
  ASM
   JMP RTL_LStrCopy
  END;

 Procedure _LStrDelete(Var S: ANSIString; Index, Count: Integer);
  ASM
   JMP RTL_LStrDelete
  END;

 Procedure _LStrInsert(Const Source: ANSIString; Var S: ANSIString; Index: Integer);
  ASM
   JMP RTL_LStrInsert
  END;

 Procedure _LStrSetLength(Var Str: ANSIString; NewLength: Integer; CodePage: Word);
  ASM
   JMP RTL_LStrSetLength
  END;

 Procedure _LStrArrayClr(Var StrArray; cnt: Longint);
  ASM
   JMP RTL_LStrArrayClr
  END;

 Function _LStrPos(Const SubStr: ANSIString; Const S: ANSIString): Integer;
  ASM
   JMP RTL_LStrPos
  END;

 //==================
 // RTL Extensions
 //==================

 Procedure RTLExtend_ANSIString(Var Ex: TRTLEx_ANSIString);
  BEGIN
   _INT_RTL_DoEx(@RTL_PCharLen, @Ex._PCharLen);
   _INT_RTL_DoEx(@RTL_LStrLen, @Ex._LStrLen);
   _INT_RTL_DoEx(@RTL_NewANSIString, @Ex._NewANSIString);
   _INT_RTL_DoEx(@RTL_LStrFromPCharLen, @Ex._LStrFromPCharLen);
   _INT_RTL_DoEx(@RTL_LStrFromChar, @Ex._LStrFromChar);
   _INT_RTL_DoEx(@RTL_LStrFromPChar, @Ex._LStrFromPChar);
   _INT_RTL_DoEx(@RTL_LStrFromArray, @Ex._LStrFromArray);
   _INT_RTL_DoEx(@RTL_LStrToPChar, @Ex._LStrToPChar);
   _INT_RTL_DoEx(@RTL_LStrAsg, @Ex._LStrAsg);
   _INT_RTL_DoEx(@RTL_LStrLAsg, @Ex._LStrLAsg);
   _INT_RTL_DoEx(@RTL_UniqueStringA, @Ex._UniqueStringA);
   _INT_RTL_DoEx(@RTL_AStrCmp, @Ex._AStrCmp);
   _INT_RTL_DoEx(@RTL_LStrCmp, @Ex._LStrCmp);
   _INT_RTL_DoEx(@RTL_LStrEqual, @Ex._LStrEqual);
   _INT_RTL_DoEx(@RTL_LStrAddRef, @Ex._LStrAddRef);
   _INT_RTL_DoEx(@RTL_LStrClr, @Ex._LStrClr);
   _INT_RTL_DoEx(@RTL_LStrCat, @Ex._LStrCat);
   _INT_RTL_DoEx(@RTL_LStrCat3, @Ex._LStrCat3);
   _INT_RTL_DoEx(@RTL_LStrCopy, @Ex._LStrCopy);
   _INT_RTL_DoEx(@RTL_LStrCatN, @Ex._LStrCatN);
   _INT_RTL_DoEx(@RTL_LStrDelete, @Ex._LStrDelete);
   _INT_RTL_DoEx(@RTL_LStrInsert, @Ex._LStrInsert);
   _INT_RTL_DoEx(@RTL_LStrSetLength, @Ex._LStrSetLength);
   _INT_RTL_DoEx(@RTL_LStrArrayClr, @Ex._LStrArrayClr);
   _INT_RTL_DoEx(@RTL_LStrPos, @Ex._LStrPos);
  END;

{$ENDIF Include_Modules_Implement}
(******************)
(* Initialization *)
(******************)
{$IFDEF Include_Modules_Initialize}
{$ENDIF Include_Modules_Initialize}
(****************)
(* Finalization *)
(****************)
{$IFDEF Include_Modules_Finalize}
{$ENDIF Include_Modules_Finalize}
